import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_app/view/news/news_list_view.dart';
import 'style/color.dart';
import 'package:flutter_app/view/tweet/tweet_list_view.dart';

import 'common/global.dart';

void main() {
  //debugPaintSizeEnabled = true;
  //执行等待数据之前要先执行这个。
  WidgetsFlutterBinding.ensureInitialized();
  Global.init().then((e) => runApp(new MaterialApp(
      title: 'Flutter Tutorial',
      home: new Center(
        child: new MyApp(),
      ))));
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
  TweetListView tweetListView = new TweetListView();
  NewsListView newsListView = new NewsListView();
  TabController controller; //tab控制器
  // int _currentIndex = 0; //选中下标
  // bool _isVisible = false;

  @override
  void initState() {
    super.initState();
    //初始化controller并添加监听
    controller = TabController(length: choices.length, vsync: this);
    // controller.addListener(() => _onTabChanged());
  }

  @override
  Widget build(BuildContext context) {
    //Scaffold是Material中主要的布局组件.
    return Stack(
      children: [
        Scaffold(
            appBar: AppBar(
              backgroundColor: m_color.black,
              title: TabBar(
                isScrollable: true,
                tabs: choices.map((Choice choice) {
                  return Tab(
                    text: choice.title,
                  );
                }).toList(),
                controller: controller,
              ),
            ),

            //body占屏幕的大部分
            body: Stack(
              children: [
                TabBarView(controller: controller, children: [
                  // Center(
                  //   child: Text("这将会是一个大家聚集聊天的地方。"),
                  // ),

                  Container(
                    decoration: BoxDecoration(
                      color: Color(0xFFEEEEEE),
                    ),
                    child: Padding(
                      padding: const EdgeInsets.all(3.0),
                      child: tweetListView,
                    ),
                  ),
                  Container(
                    decoration: BoxDecoration(
                      color: Color(0xFFEEEEEE),
                    ),
                    child: Padding(
                      padding: const EdgeInsets.all(3.0),
                      child: newsListView,
                    ),
                  ),

                  // Center(
                  //   child: Text("也许这里以后会更新一些新鲜事。"),
                  // ),
                  // Center(
                  //   child: Text("这里的内容请以后再来探索吧。"),
                  // ),
                ]),
              ],
            )),
      ],
    );
  }
}

class Choice {
  const Choice({this.title});
  final String title;
}

const List<Choice> choices = const <Choice>[
  // const Choice(title: '聊天室'),
  const Choice(title: '动态'),
  const Choice(title: '新闻'),
  // const Choice(title: '图库'),
];
